package com.sitech.portal.menus.service.impl;

import com.sitech.ibnms.core.BaseIbnmsService;
import com.sitech.portal.menus.form.UserShortcut;
import com.sitech.portal.menus.service.UserShortcutService;
import com.sitech.portal.system.dao.ISysUserShortcutDao;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.*;

/**
 * Created by leo on 15/6/3.
 */
public class UserShortcutServiceImpl extends BaseIbnmsService implements UserShortcutService {

    @Autowired
    private ISysUserShortcutDao shortcutDao;

    @Override
    public List<UserShortcut> getShortcutList() {
        List<Map<String, Object>> list = shortcutDao.findShortcutListByLoginID(getCurrentUser().getLOGIN_ID());
        List<UserShortcut> shortcuts = new ArrayList<UserShortcut>(list.size());
        for (Map<String, Object> map : list) {
            UserShortcut shortcut = new UserShortcut();
            shortcut.setMenuId((String) map.get("MODULE_ID"));
            shortcut.setShortcutName((String) map.get("SHORTCUT_NAME"));
            shortcut.setShortcutPath((String) map.get("SHORTCUT_PATH"));
            shortcuts.add(shortcut);
        }
        return shortcuts;
    }

    @Override
    public void deleteShortcut(String shortcutPath) {
        shortcutDao.deleteShortcutByPathAndLoginId(shortcutPath, getCurrentUser().getLOGIN_ID());
    }

    @Override
    public void addShortcut(UserShortcut userShortcut) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("LOGIN_ID", getCurrentUser().getLOGIN_ID());
        map.put("MODULE_ID", userShortcut.getMenuId());
        map.put("SUBMIT_TIME", new Date());
        shortcutDao.add(map);
    }
}
